﻿using ETA.IRepository;
using ETA.IService;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ETA.Service
{
    public class MBTIService : IMBTIService
    {
      #region 属性

        private IMBTIRepository _IMBTIRepository { set; get; }


        #endregion

        #region 构造函数

        public MBTIService(IMBTIRepository IMBTIRepository)
        {
            _IMBTIRepository = IMBTIRepository;
        }

        #endregion

        public QueryMBTIResponse QueryMBTIList(QueryMBTIRequest req)
        {
            var response = new QueryMBTIResponse();
            try
            {
                if (!string.IsNullOrEmpty(req.UserId) && !string.IsNullOrEmpty(req.MBTIModel))
                {
                    response.MBTIs = _IMBTIRepository.GetAllList(b => b.UserId == req.UserId && b.MBTIModel == req.MBTIModel);
                }
                else
                {
                    response.MBTIs = _IMBTIRepository.GetAllList();
                }
                response.Result.IsSuccess = true;
            }
            catch (Exception e)
            {
                response.Result.Message = e.Message;
            }
            return response;
        }

        public CreateMBTIResponse CreateMBTI(CreateMBTIRequest req)
        {
            var res = new CreateMBTIResponse();
            try
            {
                if (req != null)
                {
                    req.MBTI.MBTIId = Guid.NewGuid().ToString();
                    res.MBTI = _IMBTIRepository.Insert(req.MBTI);
                    res.Result.IsSuccess = true;
                }
            }
            catch (Exception e)
            {
                res.Result.IsSuccess = false;
                res.Result.ErrMessage = e.Message;
            }
            return res;
        }

        public ModifyMBTIResponse ModifyMBTI(ModifyMBTIRequest req)
        {
            var res = new ModifyMBTIResponse();
            try
            {
                if (req != null)
                {
                    _IMBTIRepository.Update(req.MBTI);
                    res.Result.IsSuccess = true;
                }
            }
            catch (Exception e)
            {
                res.Result.IsSuccess = false;
                res.Result.ErrMessage = e.Message;
            }
            return res;
        }
    }
}
